<?php

/**
 * goods_inventory_model short summary.
 *
 * goods_inventory_model description.
 *
 * @version 1.0
 * @author GALAXY
 */
class Goods_inventory_model extends CI_Model
{
    public $goods_inventory_id;
    public $goods_id;
    public $goods_size_id;
    public $goods_color_id;
    public $inventory_count;
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function insert_goods_inventory($goodsinventoryModel)
    {
        return $this->db->insert('goods_inventory',$goodsinventoryModel);
    }
    public function update_goods_inventory($goodsinventoryModel)
    {
        return $this->db->update('goods_inventory',$goodsinventoryModel,array('goods_inventory_id'=>$goodsinventoryModel->goods_inventory_id));
    }

    public function get_inventory($goodsinventoryModel)
    {
        return $this->db->select()->from('goods_inventory')->where("goods_id=".$goodsinventoryModel->goods_id." and goods_size_id=".$goodsinventoryModel->goods_size_id." and goods_color_id=".$goodsinventoryModel->goods_color_id)->get()->result();
    }

    public function del_goods_inventory($goodsinventoryModel)
    {
        return $this->db->delete(array('goods_inventory_id'=>$goodsinventoryModel->goods_inventory_id));
    }

    public function get_inventory_val($goodsinventoryModel)
    {
        return $this->db->select()->from('goods_inventory')->where("goods_id=".$goodsinventoryModel->goods_id." and goods_size_id=".$goodsinventoryModel->goods_size_id." and goods_color_id=".$goodsinventoryModel->goods_color_id)->get()->row();
    }

    public function get_goods_inventory_count($goodscart_model)
    {
        $sql="select inventory_count from goods_inventory where goods_color_id=".$goodscart_model->color_id." and goods_size_id=".$goodscart_model->size_id." and goods_id=".$goodscart_model->goods_id;
        return $this->db->query($sql)->row();
    }


    public function get_first_goods_by_goods_id($goods_id)
    {
        $sql="select * from goods_inventory where goods_id=$goods_id limit 1";
        return $this->db->query($sql)->row();
    }
}